package simulatorGUI;
import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JLabel;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import everything.WorldMap;

import markov.MDPStateTable;

/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class Header extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	HeaderPanel p;
	Combinations p1;
	pnlMarkovView p2;
	private JTabbedPane jTabbedPane1;

	public Header(int numRegions, WorldMap m, int[] icyPatches, int[] flags, MDPStateTable[] st, boolean remember){
		super("Probabilities");
		int rowSize = m.getWidth();
		setAlwaysOnTop(true);
		{
			jTabbedPane1 = new JTabbedPane();
			getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
			p = new HeaderPanel(numRegions);
			p1 = new Combinations(rowSize, icyPatches);
			p2 = new pnlMarkovView(flags, icyPatches, m, st, remember);
			jTabbedPane1.insertTab("Probabilities1", null, p, "BWABABA", 0);
			jTabbedPane1.insertTab("Joint", null, p1, "BWABABA", 1);
			jTabbedPane1.insertTab("Markov", null, new JScrollPane(p2), "BWABABA", 2);
//			jTabbedPane1.add(p, 0);
		}
	}
	
	public void updateProbSeason(float summerProb, float winterProb){
		p.updateProbSeason(summerProb, winterProb);
	}
	
	public void updateProbClimate(int region, float warmProb, float coldProb, float frigidProb){
		p.updateProbClimate(region, warmProb, coldProb, frigidProb);
	}
	
	public void updateProbJoint(float[][] probabilities){
		p1.updateProbJoint(probabilities);
	}
	
//	public void updateProbClimateWinter(int region, float warmProb, float coldProb, float frigidProb){
//		p.updateProbClimateWinter(region, warmProb, coldProb, frigidProb);
//	}

	private class HeaderPanel extends JPanel{
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		private JScrollPane jScrollPane1;
		private JScrollPane jScrollPane2;
		private JLabel jLabel1;
		private JLabel lblSeason;
		private JTable jTable2;
		private JTable jTable1;

		public HeaderPanel(int numRegions){
			initGUI(numRegions);
		}
		
		public void updateProbSeason(float summerProb, float winterProb){
			jTable2.getModel().setValueAt(""+summerProb, 0, 0);
			jTable2.getModel().setValueAt(""+winterProb, 0, 1);
		}
		
		public void updateProbClimate(int region, float warmProb, float coldProb, float frigidProb){
			jTable1.getModel().setValueAt(""+warmProb, region, 1);
			jTable1.getModel().setValueAt(""+coldProb, region, 2);
			jTable1.getModel().setValueAt(""+frigidProb, region, 3);
		}
		
//		public void updateProbClimateWinter(int region, float warmProb, float coldProb, float frigidProb){
//			jTable2.getModel().setValueAt(""+warmProb, region, 4);
//			jTable2.getModel().setValueAt(""+coldProb, region, 5);
//			jTable2.getModel().setValueAt(""+frigidProb, region, 6);
//		}

		private void initGUI(int numRegions) {
			try {
				{
					this.setPreferredSize(new java.awt.Dimension(670, 252));
					this.setLayout(null);
					this.setBackground(Color.GRAY);
					this.setSize(670, 252);
					{
						jScrollPane1 = new JScrollPane();
						this.add(jScrollPane1);
						jScrollPane1.setBounds(20, 117, 484, 90);
						{
							String[][] tmp = new String[numRegions][4];
							for (int i=0; i<tmp.length; i++){
								tmp[i][0] = (i+1)+"";
								tmp[i][1] = "0";
								tmp[i][2] = "0";
								tmp[i][3] = "0";
							}
							TableModel jTable1Model = 
								new DefaultTableModel(
//										new String[][] { { "1", "0.1", "0.1", "0.5", "0.5", "0.5", "0.5"}, { "2", "0.5", "0.5", "0.5", "0.5", "0.5", "0.5" } },
//										new String[] { "Region", "WS", "CS", "FS" , "WW", "CW", "FW"}){
//										new String[][] { { "1", "0.1", "0.1", "0.5"}, { "2", "0.5", "0.5", "0.5" } },
										tmp,
										new String[] { "Region", "Warm", "Cold", "Frigid"}){
								/**
								 * 
								 */
								private static final long serialVersionUID = 1L;

								@Override
								public boolean isCellEditable(
										int row, int column) {
									return false;
								}
							};
							jTable1 = new JTable();
//							ScrollPaneLayout l = new ScrollPaneLayout();
							jScrollPane1.setViewportView(jTable1);
							jTable1.setModel(jTable1Model);
						}
					}
					{
						jScrollPane2 = new JScrollPane();
						this.add(jScrollPane2);
						jScrollPane2.setBounds(20, 25, 306, 55);
						{
							TableModel jTable2Model = 
								new DefaultTableModel(
										new String[][] { { "0.3", "0.7" }},
										new String[] { "Summer", "Winter" }){
								/**
								 * 
								 */
								private static final long serialVersionUID = 1L;

								@Override
								public boolean isCellEditable(
										int row, int column) {
									return false;
								}
							};
							jTable2 = new JTable();
							jScrollPane2.setViewportView(jTable2);
							jTable2.setModel(jTable2Model);
							//jTable2.setPreferredSize(new java.awt.Dimension(235, 15));
						}
					}
					{
						lblSeason = new JLabel();
						this.add(lblSeason);
						lblSeason.setText("Season:");
						lblSeason.setBounds(5, 3, 58, 20);
						lblSeason.setFont(new java.awt.Font("Tahoma",1,14));
					}
					{
						jLabel1 = new JLabel();
						this.add(jLabel1);
						jLabel1.setText("Climate:");
						jLabel1.setFont(new java.awt.Font("Tahoma",1,14));
						jLabel1.setBounds(5, 88, 58, 20);
					}
				}
			} catch(Exception e) {
				e.printStackTrace();
			}
		}

	}

	public void setStateTable(MDPStateTable[] st) {
		p2.setStateTable(st);
	}
}
